//
//  AllCommentViewController.m
//  CarLife
//
//  Created by yu on 2019/4/2.
//  Copyright © 2019年 jpas. All rights reserved.
//

#import "AllCommentViewController.h"
#import "AllCommentCell.h"

static NSString *kACCellIdentifier = @"ACCellIdentitifier";

@interface AllCommentViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@end

@implementation AllCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"4条回复";
    [self.tableView registerNib:NIB_NAMED(@"AllCommentCell") forCellReuseIdentifier:kACCellIdentifier];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return !section ? 1 : self.dataSource.count + 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AllCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:kACCellIdentifier];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.tableView cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:[AllCommentCell class] contentViewWidth:[self cellContentViewWith]];;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return !section ? 0.001 : 45.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section) {
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = kBackgroundColor;
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, 39.5)];
        view.backgroundColor = [UIColor whiteColor];
        [bgView addSubview:view];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(17, 0, kScreenWidth - 17, 39.5)];
        label.text = @"全部回复";
        label.font = Font_NAME_SIZE(@"PingFangSC-Medium", 16.5);
        [view addSubview:label];
        return bgView;
    }
    return nil;
}

- (CGFloat)cellContentViewWith
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    // 适配ios7横屏
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
        width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setWhiteNavigationBar];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self setDefaultNavigationBar];
}

- (NSMutableArray *)dataSource
{
    if (_dataSource == nil) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

@end
